﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DataTransfer;
namespace Gui
{
    public partial class frmDanhSachNhanVien : DevComponents.DotNetBar.Office2007Form
    {
        public UserBus userBus;
        public frmDanhSachNhanVien()
        {
            InitializeComponent();
        }

        private void frmDanhSachNhanVien_Load(object sender, EventArgs e)
        {
            load();
        }
        public void load()
        {
            userBus = new UserBus();
            dtgDanhSachNhanVien.DataSource = userBus.GetAll();
            dtgDanhSachNhanVien.Columns["Pass"].Visible = false;
        }
        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnThemNhanVien_Click(object sender, EventArgs e)
        {
            Form frm = new frmThemNhanVien(this);
            frm.ShowDialog();
        }

        private void btnXoaNhanVien_Click(object sender, EventArgs e)
        {
            User info = new User();
            getItem(ref info);
            userBus = new UserBus();
            userBus.Delele(info.UserName);
            load();
        }

        private void btnSuaNhanVien_Click(object sender, EventArgs e)
        {
            User info = new User();
            getItem(ref info);
            Form frm = new frmThemNhanVien(this,info);
            frm.ShowDialog();
        }

        private bool getItem(ref User info)
        {
            bool flag = false;
            int index = dtgDanhSachNhanVien.CurrentRow.Index;
            if (index >= 0)
            {
                info.UserName = dtgDanhSachNhanVien["UserName", index].Value.ToString();
                info.Pass = dtgDanhSachNhanVien["Pass", index].Value.ToString();
                info.act = Convert.ToInt32( dtgDanhSachNhanVien["act", index].Value.ToString());
                info.HoTen = dtgDanhSachNhanVien["HoTen", index].Value.ToString();
                info.GioiTinh = Convert.ToInt32(dtgDanhSachNhanVien["GioiTinh", index].Value.ToString());
                info.NgaySinh = Convert.ToDateTime(dtgDanhSachNhanVien["NgaySinh", index].Value.ToString());
                
                
                flag = true;
            }
            if (flag == false)
            {
                MessageBox.Show("Chua chon Item");
            }
            return flag;
        }
    }
}
